package examples.distributedsession.support;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * @author Bill
 * @version 2013-05-28
 */
public class CookieHelper {

    public static final String DISTRIBUTED_SESSION_ID = "DISTRIBUTED_SESSION_ID";

    private CookieHelper() {
    }

    public static String findSessionId(HttpServletRequest request) {
        if (request == null) {
            return null;
        }
        String ret = null;
        for (Cookie cookie : request.getCookies()) {
            if (DISTRIBUTED_SESSION_ID.equals(cookie.getName())) {
                ret = cookie.getValue();
                break;
            }
        }
        return ret;
    }

}
